package sc.analysis.vortex;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.VIntWritable;
import org.apache.hadoop.io.Writable;

/**
 * Used to store data between the mapper and the reducer of Vortex.
 * 
 * @author Quentin Rossé
 *
 */
public class VortexData implements Writable{
	
	/**
	 * used to write integers
	 */
	private static VIntWritable vint = new VIntWritable();
	
	/**
	 * Period for this Vortex analysis
	 */
	private int period;
	
	/**
	 * Value of down
	 */
	private float down;
	
	/**
	 * Value of up
	 */
	private float up;
	
	/**
	 * Days since the last cross of the indicator (-1 if there were no recent
	 * cross)
	 */
	private int daysSinceCross;
	
	
	public VortexData(){}
	
	public VortexData(int period, float down, float up, int daysSinceCross) {
		this.period = period;
		this.down = down;
		this.up = up;
		this.daysSinceCross = daysSinceCross;
	}

	public int getPeriod() {
		return period;
	}

	public void setPeriod(int period) {
		this.period = period;
	}

	public float getDown() {
		return down;
	}

	public void setDown(float down) {
		this.down = down;
	}

	public float getUp() {
		return up;
	}

	public void setUp(float up) {
		this.up = up;
	}
	
	public int getDaysSinceCross() {
		return daysSinceCross;
	}

	public void setDaysSinceCross(int daysSinceCross) {
		this.daysSinceCross = daysSinceCross;
	}

	public void setAll(int period, float down, float up, int daysSinceCross) {
		this.period = period;
		this.down = down;
		this.up = up;
		this.daysSinceCross = daysSinceCross;
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		vint.readFields(in);
		period = vint.get();
		down = in.readFloat();
		up = in.readFloat();
		vint.readFields(in);
		daysSinceCross = vint.get();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		vint.set(period);
		vint.write(out);
		out.writeFloat(down);
		out.writeFloat(up);
		vint.set(daysSinceCross);
		vint.write(out);
	}

}
